package es.ucm.fdi.isbc.viviendas.gui;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import es.ucm.fdi.isbc.viviendas.representacion.DescripcionVivienda;
import es.ucm.fdi.isbc.viviendas.representacion.ExtrasOtros;

@SuppressWarnings("serial")
public class PanelExtrasOtros extends JPanel{

	private JCheckBox box_patio;
	private JCheckBox box_balcon;
	private JCheckBox box_zonaDeportiva;
	private JCheckBox box_zonaComunitaria;
	private JCheckBox box_terraza;
	private JCheckBox box_piscinaComunitaria;
	private JCheckBox box_jardinPrivado;
	private JCheckBox box_zonaInfantil;
	private JCheckBox box_piscina;
	
	public PanelExtrasOtros(){
		
		setLayout(new GridBagLayout());
		GridBagConstraints c=new GridBagConstraints();
		c.gridx=0;/*posicion x de la tabla*/
		c.gridy=0;/*posicion y de la tabla*/
		c.gridwidth = 1; /*anchura en celdas*/
		c.gridheight = 1;/*altura en celdas*/
		
		c.insets=new Insets(3,3,3,3);
		
		/*creo todos los labels que se mostraran en la ventana*/
		JLabel label_patio=new JLabel("Patio");
		JLabel label_balcon=new JLabel("Balcon");
		JLabel label_zonaDeportiva=new JLabel("Zona Deportiva");
		JLabel label_zonaComunitaria=new JLabel("Zona Comunitaria");
		JLabel label_terraza=new JLabel("Terraza");
		JLabel label_piscinaComunitaria=new JLabel("Piscina Comunitaria");
		JLabel label_jardinPrivado=new JLabel("Jardin Privado");
		JLabel label_zonaInfantil=new JLabel("Zona Infantil");
		JLabel label_piscina=new JLabel("Piscina");
		
		/*coloco los labels en la ventana*/
		c.anchor=GridBagConstraints.EAST;
		c.gridy=0;
		this.add(label_patio, c);
		c.gridy=1;
		this.add(label_balcon, c);
		c.gridy=2;
		this.add(label_zonaDeportiva, c);
		c.gridy=3;
		this.add(label_zonaComunitaria, c);
		c.gridy=4;
		this.add(label_terraza, c);
		c.gridx=2;
		c.gridy=0;
		this.add(label_piscinaComunitaria, c);
		c.gridy=1;
		this.add(label_jardinPrivado, c);
		c.gridy=2;
		this.add(label_zonaInfantil, c);
		c.gridy=3;
		this.add(label_piscina, c);
		
		
		
		/*inicializamos los checkboxes que se mostraran en la ventana*/
		box_patio=new JCheckBox();
		box_balcon=new JCheckBox();
		box_zonaDeportiva=new JCheckBox();
		box_zonaComunitaria=new JCheckBox();
		box_terraza=new JCheckBox();
		box_piscinaComunitaria=new JCheckBox();
		box_jardinPrivado=new JCheckBox();
		box_zonaInfantil=new JCheckBox();
		box_piscina=new JCheckBox();
		
		/*colocamos los checkboxes en la ventana*/
		c.gridx=1;
		c.gridy=0;
		this.add(box_patio, c);
		c.gridy=1;
		this.add(box_balcon, c);
		c.gridy=2;
		this.add(box_zonaDeportiva, c);
		c.gridy=3;
		this.add(box_zonaComunitaria, c);
		c.gridy=4;
		this.add(box_terraza, c);
		c.gridx=3;
		c.gridy=0;
		this.add(box_piscinaComunitaria, c);
		c.gridy=1;
		this.add(box_jardinPrivado, c);
		c.gridy=2;
		this.add(box_zonaInfantil, c);
		c.gridy=3;
		this.add(box_piscina, c);

	}
	
	public void rellenarQuery(DescripcionVivienda q){
		ExtrasOtros eo = new ExtrasOtros(1);
		if(box_patio.isSelected())
			eo.setPatio(box_patio.isSelected());
		if(box_balcon.isSelected())
			eo.setBalcon(box_balcon.isSelected());
		if(box_zonaDeportiva.isSelected())
			eo.setZonaDeportiva(box_zonaDeportiva.isSelected());
		if(box_zonaComunitaria.isSelected())
			eo.setZonaComunitaria(box_zonaComunitaria.isSelected());
		if(box_terraza.isSelected())
			eo.setTerraza(box_terraza.isSelected());
		if(box_piscinaComunitaria.isSelected())
			eo.setPiscinaComunitaria(box_piscinaComunitaria.isSelected());
		if(box_jardinPrivado.isSelected())
			eo.setJardinPrivado(box_jardinPrivado.isSelected());
		if(box_zonaInfantil.isSelected())
			eo.setZonaInfantil(box_zonaInfantil.isSelected());
		if(box_piscina.isSelected())
			eo.setPiscina(box_piscina.isSelected());
		q.setExtrasOtros(eo);
		}
	
	public void reset(){
		box_patio.setSelected(false);
		box_balcon.setSelected(false);
		box_zonaDeportiva.setSelected(false);
		box_zonaComunitaria.setSelected(false);
		box_terraza.setSelected(false);
		box_piscinaComunitaria.setSelected(false);
		box_jardinPrivado.setSelected(false);
		box_zonaInfantil.setSelected(false);
		box_piscina.setSelected(false);
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Panel Filtro");
        frame.setLayout(new BorderLayout());
        frame.setResizable(false);
        //frame.setSize(800, 700);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.setLocationRelativeTo(null);
   
        
        //Add content to the window.
        frame.add(new PanelExtrasOtros(),BorderLayout.CENTER);
      

        //Display the window.
        frame.pack();
        frame.setVisible(true);

	}

}
